package com.simplystupid.expensestracking;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;

public class ListExpenses extends ListActivity {
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		Cursor c = getContentResolver().query(MyExpensesAuthority.CONTENT_URI,
				new String[] { BaseColumns._ID,
						MyExpensesProvider.DESCRIPTION,
						MyExpensesProvider.AMOUNT }, 
				null, null, 
				MyExpensesProvider.EXPENSES_DATE + " DESC");
		startManagingCursor(c);
		
		SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
				R.layout.my_expenses_item, 
				c, 
				new String[] {
						MyExpensesProvider.DESCRIPTION,
						MyExpensesProvider.AMOUNT }, 
				new int[] { R.id.item_desc, R.id.item_amount });
		
		setListAdapter(adapter);
		
		Button addBtn = (Button) findViewById(R.id.add_expenses);
		addBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent editExpensesIntent = new Intent("intent.action.ADD_EXPENSES");
				startActivity(editExpensesIntent);
			}
		});
		
	}

}